﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddEdit.aspx.cs" Inherits="CardLogistics.Web.MainPage.CardMaking.CardSeparate.AddEdit" %>

<%@ Register Src="../../../Controls/WebUserControl_Nav.ascx" TagName="WebUserControl_Nav"
    TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>离盒操作-编辑</title>
    <link href="../../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/selPage.css" rel="stylesheet" type="text/css" />
    <script src="../../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../../js/valReq.js" type="text/javascript"></script>
    <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../js/jquery.tipswindow.2.0.js" type="text/javascript"></script>
    <script type="text/javascript">
        function valReq(issubmit) {
            var altStr = valid_isempty('SEPARATENO', '离盒单号');
            altStr += GetCardInfo();
            altStr += valid_isempty('hf_separatId', '明细信息');
            if (altStr != "") {
                alert(altStr);
                return false;
            }
            else {
                if (issubmit == 1) {
                    if (confirm("提交后该信息进入待审批状态不可编辑,确认提交吗?") == true) {
                        return true;
                    }
                    else
                        return false;
                }
                else
                    return true;
            }
        }

    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            //输入结束卡号时，自动计算实际数量
            $("input[name='EndNo']").keyup(function () {
                var endNO = this.value; //当前值-EndNO结束卡号
                var tr = this.parentNode.parentNode; //当前行
                var startNO = $(tr.cells[3]).find("input").val(); //起始卡号StartNO
                var ActualNumber = 0; //计算单个实际数量
                if (startNO.toString().length == 8 && parseInt(endNO) >= parseInt(startNO)) {
                    ActualNumber = parseInt(endNO) - parseInt(startNO) + 1;
                    $(tr.cells[6]).find("input").val(ActualNumber); //实际数量赋值
                } else {
                    $(tr.cells[6]).find("input").val(0); //实际数量赋值
                    $(tr.cells[5]).find("input").val(0); //应有数量赋值
                }
            });
            //汇总实际数量
            $("input[name='ActualNumber']").keyup(function () {
                document.getElementById("ActualSum").innerHTML = GetSumByName("ActualNumber"); //实际数量合计
            });
            //根据开始卡号默认结束卡号计算应有数量
            $("#tb_Detail").keyup(function () {
                var DeservedNumber = $("input[name=DeservedNumber]"); //应有数量
                var ActualNumber = $("input[name=ActualNumber]"); //实际数量
                var StartNo = $("input[name=StartNo]"); //开始卡号
                var EndNo = $("input[name=EndNo]"); //结束卡号
                $("input[name='StartNo']").each(function (i, o) {
                    if (Trim($(StartNo[i]).val()).length == 8 && Trim($(EndNo[i]).val()).length == 8 && parseInt(Trim($(EndNo[i]).val())) >= parseInt(Trim($(StartNo[i]).val()))) {
                        var yy = parseInt(Trim($(EndNo[i]).val())) - parseInt(Trim($(StartNo[i]).val())) + 1;
                        if ($(DeservedNumber[i]).val() == "" || $(DeservedNumber[i]).val() == "0") {
                            if ($(ActualNumber[i]).val() == "" || $(ActualNumber[i]).val() == "0") {
                                $(ActualNumber[i]).val(yy); //实际数量
                            }
                        }
                        $(DeservedNumber[i]).val(yy); //应有数量
                    } else {
                        $(DeservedNumber[i]).val(0); //应有数量
                        $(ActualNumber[i]).val(0); //实际数量
                    }
                });
                //合计
                GetSumInfo();
            });
        })
        //合计
        function GetSumInfo() {
            document.getElementById("DueSum").innerHTML = GetSumByName("DeservedNumber"); //应有数量合计
            document.getElementById("ActualSum").innerHTML = GetSumByName("ActualNumber"); //实际数量合计
        }
        //保存时获取明细数据
        function GetCardInfo() {
            var Data_value = [];
            var errInfo = ""; //返回错误消息
            var vIndex = 0;
            var BoxNo = $("input[name=BoxNo]"); //箱号
            var CardNo = $("input[name=CardNo]"); //盒号
            var StartNo = $("input[name=StartNo]"); //开始卡号
            var EndNo = $("input[name=EndNo]"); //结束卡号
            var DeservedNumber = $("input[name=DeservedNumber]"); //应有数量
            var ActualNumber = $("input[name=ActualNumber]"); //实际数量
            var MissingCardNo = $("input[name=MissingCardNo]"); //缺卡卡号
            $("input[name='BoxNo']").each(function (i, o) {
                if (($(BoxNo[i]).val() != "0" && $(BoxNo[i]).val() != "")) {
                    Data_value[vIndex] = "'" + Trim($(o).val()) + "'|'" + Trim($(CardNo[i]).val()) + "'|'" + Trim($(StartNo[i]).val())
                    + "'|'" + Trim($(EndNo[i]).val()) + "'|" + Trim($(DeservedNumber[i]).val()) + "|" + Trim($(ActualNumber[i]).val()) + "|" + "'" + Trim($(MissingCardNo[i]).val()) + "'"; //字段值
                    vIndex++;
                    if (Trim($(o).val()) == "" || ($(CardNo[i]).val() == "0" || ($(CardNo[i]).val() == "")) || ($(StartNo[i]).val() == "0" || ($(StartNo[i]).val() == "")) ||
                     ($(EndNo[i]).val() == "0" || ($(EndNo[i]).val() == "")) || ($(DeservedNumber[i]).val() == "0" || ($(DeservedNumber[i]).val() == "")) || ($(ActualNumber[i]).val() == "0" || ($(ActualNumber[i]).val() == ""))) {
                        errInfo += "第" + vIndex + "行明细不能为空\n";
                    }
                    //判断实际数量不能超过应有数量
                    if (parseInt(Trim($(ActualNumber[i]).val())) > parseInt(Trim($(DeservedNumber[i]).val()))) {
                        errInfo += "第" + vIndex + "行实际数量不能超过应有数量\n";
                    }
                }
            });
            $("#hf_separatId").val(Data_value.join(";"));
            return errInfo;
        }

        //修改时绑定明细数据
        function BindDetailInfo() {
            var BoxNo = $("input[name=BoxNo]");
            var CardNo = $("input[name=CardNo]");
            var StartNo = $("input[name=StartNo]");
            var EndNo = $("input[name=EndNo]");
            var DeservedNumber = $("input[name=DeservedNumber]");
            var ActualNumber = $("input[name=ActualNumber]");
            var MissingCardNo = $("input[name=MissingCardNo]");
            var ids = document.getElementById("hf_separatId").value;
            var str1 = ids.split(";");
            for (var i = 0; i < str1.length; i++) {
                if (str1[i] != "") {
                    $(BoxNo[i]).val(str1[i].split("|")[0].replace("'", "").replace("'", "")); //箱号
                    $(CardNo[i]).val(str1[i].split("|")[1].replace("'", "").replace("'", "")); //盒号
                    $(StartNo[i]).val(Pad(str1[i].split("|")[2].replace("'", "").replace("'", ""), 8)); //开始卡号
                    $(EndNo[i]).val(Pad(str1[i].split("|")[3].replace("'", "").replace("'", ""), 8)); //结束卡号
                    $(DeservedNumber[i]).val(str1[i].split("|")[4]); //应有数量
                    $(ActualNumber[i]).val(str1[i].split("|")[5]); //实际数量
                    $(MissingCardNo[i]).val(str1[i].split("|")[6].replace("'", "").replace("'", "")); //缺卡卡号
                }
            }
            //合计
            GetSumInfo();
        }
        window.onload = function () { BindDetailInfo(); }
    </script>
</head>
<body>
    <form id="frmSeparate" runat="server">
    <input type="hidden" id="hf_separatId" runat="server" />
    <uc1:WebUserControl_Nav ID="WebUserControl_Nav1" runat="server" />
    <%=TitleName %>
    <table class="theFormM" width="100%" border="0" cellspacing="0" cellpadding="0" style="line-height: 20px;">
        <tr>
            <td class="titleTxt">
                离盒单号：
            </td>
            <td class="contentTxtM">
                <input id="SEPARATENO" runat="server" type="text" class="dfinputNoEmp" maxlength="25" />
            </td>
            <td class="titleTxt">
                操作人：
            </td>
            <td class="contentTxtM">
                <input id="SEPARATEUSER" runat="server" type="text" class="dfinputNoEmp" readonly="readonly"
                    maxlength="25" />
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                操作时间：
            </td>
            <td class="contentTxtM">
                <input id="SEPARATEDATE" runat="server" type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
            </td>
            <td class="titleTxt">
                备注：
            </td>
            <td colspan="2">
                <input id="REMARKS" runat="server" type="text" maxlength="200" class="dfinput" style="width: 75%;" />
            </td>
        </tr>
        <tr>
            <td colspan="8" style="text-align: left; border: 1px;">
            </td>
        </tr>
        <tr>
            <td colspan="8">
                <div class="ddetail">
                    <table class="tabledetail" id="tb_Detail">
                        <thead>
                            <tr>
                                <th width="70px">
                                    序号
                                </th>
                                <th width="110px">
                                    箱号
                                </th>
                                <th width="110px">
                                    盒号
                                </th>
                                <th width="110px">
                                    起始卡号
                                </th>
                                <th width="110px">
                                    结束卡号
                                </th>
                                <th width="110px">
                                    应有数量/张
                                </th>
                                <th width="110px">
                                    实际数量/张
                                </th>
                                <th>
                                    缺卡卡号
                                </th>
                                <th>
                                    &nbsp;
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tablebody">
                            <tr>
                                <td width="70px" align="center">
                                    1
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    2
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    3
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    4
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    5
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    6
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    7
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    8
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    9
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="70px" align="center">
                                    10
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="CardNo" type="text" class="dfinput" onkeydown="onlyNumCode();" maxlength="11" />
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" onkeydown="onlyNum();" maxlength="8" />
                                </td>
                                <td>
                                    <input name="DeservedNumber" readonly="readonly" type="text" class="dfinput" value="0"
                                        onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" onkeydown="onlyNum();"
                                        maxlength="9" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" onkeyup="onlyMisCard(this);" type="text" class="dfinput" />
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <table class="tablesum">
                    <tr>
                        <th width="81px">
                            &nbsp;
                        </th>
                        <th width="111px" style="text-align: center;">
                            合计
                        </th>
                        <th width="111px">
                            &nbsp;
                        </th>
                        <th width="111px">
                            &nbsp;
                        </th>
                        <th width="111px">
                            &nbsp;
                        </th>
                        <th width="111px" style="text-align: right;" id="DueSum">
                            0
                        </th>
                        <th width="111px" style="text-align: right;" id="ActualSum">
                            0
                        </th>
                        <th>
                            &nbsp;
                        </th>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="8" align="center" style="height: 55px;">
                <asp:Button ID="btn_Submit" CssClass="btn" runat="server" Text="保存并提交" OnClientClick="return valReq(1);"
                    OnClick="btn_Submit_Click" />
                <asp:Button ID="btn_Add" CssClass="btn" runat="server" Text="保存" OnClientClick="return valReq(0);"
                    OnClick="btn_Add_Click" />
                <input type="button" class="btn" value="返回" onclick="javascript:history.go(-1);" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
